package lumis.service.chatroom;

import org.hibernate.Session;

import lumis.collaboration.chat.ChatManagerFactory;
import lumis.doui.processaction.ProcessActionHandler;
import lumis.portal.AccessDeniedException;
import lumis.portal.PortalException;
import lumis.portal.dao.hibernate.ITransactionHibernate;

/**
 * Handles deletion of chat rooms
 *
 * @version $Revision: 4482 $ $Date: 2006-09-18 18:33:56 -0300 (Mon, 18 Sep 2006) $
 * @since 4.0.6
 */
public class DeleteChatRoomProcessActionHandler extends ProcessActionHandler
{
	public void processAction() throws PortalException
	{
		if(!checkServiceInstancePermission("editContent"))
			throw new AccessDeniedException();

		ITransactionHibernate transactionHib = (ITransactionHibernate) transaction;
		Session session = transactionHib.getSession();
		
		String[] chatRoomIds = (String[])this.getParameter("id");
		
		for(String chatRoomId : chatRoomIds)
		{
			ChatRoomConfig chatRoomConfig = (ChatRoomConfig)session.get(ChatRoomConfig.class,chatRoomId);
			
			// notify chat manager to delete the conversation
			ChatManagerFactory.getChatManager().deleteConversation(sessionConfig, chatRoomConfig.getChatConversationId(), transaction);
		}
		
		addDefaultResponse();
	}

}
